package dp.dayOne;

public class TwoQuestion {
    public static void main(String[] args) {

    }
    //太波那切数列
    /*泰波那契序列Tn定义如下：

T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0的条件下 Tn+3 = Tn + Tn+1 + Tn+2

给你整数n，请返回第 n 个泰波那契数Tn 的值。*/
    public int tribonacci(int n) {
        if (n<=1){
            return n;
        }
        if (n==2){
            return 2;
        }
        //大于等于3的时候
        int per1 = 1,per2=1,per3=0,result =0;
        for (int i = 3; i <= n; i++) {
            result = per1+per2+per3;
            per3 = per2;
            per2 = per1;
            per1 = result;
        }
        return result;
    }
}
